home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 11: TSX-11
/
Linux Cubed Series 11 - TSX-11 Vol 1.iso
/
usr.bin
/
tty.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-30
|
3KB
|
134 lines
This is a version of tty.c for linux.
john harvey JOHNBOB at AUSVMQ I don't speak for my employer.
johnbob@innerdoor.austin.ibm.com johnbob@there.austin.ibm.com
johnbob@129.35.81.111 johnbob@129.35.81.200
main(int c,char**v){if(c==2){int n=atoi(v[1]);printf("%d\n",
n*main(-n+1,v));}else if(c<0)return-c*main(c+1,v);return 1;}
---- Cut Here and unpack ----
#!/bin/sh
# This is a shell archive (shar 3.10)
# made 01/21/1992 18:47 UTC by rjohnbobpts/4@AIX
# Source directory /drive2/u/johnbob/net/linux/contrib
#
# existing files will NOT be overwritten
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 170 -rw-r--r-- Makefile
# 158 -rw-r--r-- add.this
# 587 -rw-r--r-- tty.c
#
touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
if [ -s /tmp/s3_touch$$ ]
then
TOUCH=can
else
TOUCH=cannot
fi
rm -f /tmp/s3_touch$$
# ============= Makefile ==============
if test -f Makefile; then echo "File Makefile exists"; else
echo "x - extracting Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X#
X#
X
XPROGRAM = tty
XSRC = tty.c
XOBJS = tty.o
X
XCC=cc
XCFLAGS = -O
X
X
Xall: $(PROGRAM)
X
X$(PROGRAM): $(OBJS)
X $(CC) -o $(PROGRAM) $(OBJS) $(LIBS)
X
X.c.o:
X $(CC) $(CFLAGS) -c $<
X
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
if [ $TOUCH = can ]
then
touch -am 0120162992 Makefile
fi
fi
# ============= add.this ==============
if test -f add.this; then echo "File add.this exists"; else
echo "x - extracting add.this (Text)"
sed 's/^X//' << 'SHAR_EOF' > add.this &&
XThe prototype for the ttyname() function wasn't in
X/usr/include/unistd.h so you will have to add it to
Xthe bottom of the file:
X
Xchar * ttyname(int fildes);
X
X
SHAR_EOF
chmod 0644 add.this || echo "restore of add.this fails"
if [ $TOUCH = can ]
then
touch -am 0120174392 add.this
fi
fi
# ============= tty.c ==============
if test -f tty.c; then echo "File tty.c exists"; else
echo "x - extracting tty.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > tty.c &&
X/*
X tty.c
X By John Harvey AKA johnbob AKA qk
X copy this all you want
X*/
X
X#include <sys/types.h>
X#include <stdio.h>
X#include <unistd.h>
X
Xvoid syntax(int rv)
X{
X fprintf(stderr,"syntax: tty [-s]\n");
X exit(rv);
X}
X
Xmain(int argc, char **argv)
X{
X int silent = 0;
X char *n;
X
X if( argc == 2 )
X {
X if( strcmp(argv[1],"-s") )
X syntax(1);
X silent = 1;
X }
X else if ( argc != 1 )
X syntax(1);
X if( n=ttyname(0) )
X {
X if ( ! silent )
X printf("%s\n", n);
X exit(0);
X }
X else
X {
X if ( ! silent )
X printf("%s\n", "Not a tty");
X exit(1);
X }
X}
SHAR_EOF
chmod 0644 tty.c || echo "restore of tty.c fails"
if [ $TOUCH = can ]
then
touch -am 0120173492 tty.c
fi
fi
exit 0